<template>
  <el-table :data="fileList" stripe>
    <el-table-column label="附件名称" prop="orgFileName">
      <template #default="{ row }">
        <div class="large-link" @click="handleClick(row)">
          {{ row.orgFileName }}
        </div>
      </template>
    </el-table-column>
    <el-table-column label="上传单位" prop="unitName" />
    <el-table-column label="上传人" prop="createUserName" />
    <el-table-column label="上传时间" prop="createTime">
      <template #default="{ row }">
        {{ formatDateStr(row.createTime, 'YYYY年MM月DD日') }}
      </template>
    </el-table-column>
    <el-table-column label="材料大小" prop="fileSize">
      <template #default="{ row }">
        {{ formatBytes(row.fileSize) }}
      </template>
    </el-table-column>
  </el-table>
</template>

<script lang="ts" setup>
import { formatDateStr } from '@/plugins/date'
import { formatBytes } from '@/plugins/file'
import { ref } from 'vue'

withDefaults(
  defineProps<{
    fileList: Record<string, any>[]
  }>(),
  {
    fileList: () => [],
  },
)

const fileUrl = ref('/supervision-api/fileController/fileDownload')

const handleClick = (row) => {
  const url = `${fileUrl.value}/${row.id}`
  window.open(url, '_blank')
}
</script>
